/*
You are attempting to solve a Coding Contract. You have 10 tries remaining, after which the contract will self-destruct.


Given the following string containing only digits, return an array with all possible valid IP address combinations that can be created from the string:

190104114239

Note that an octet cannot begin with a '0' unless the number itself is actually 0. For example, '192.168.010.1' is not a valid IP.

Examples:

25525511135 -> ["255.255.11.135", "255.255.111.35"]
1938718066 -> ["193.87.180.66"]
*/

// 好办的一点是:题目没有零
// 关键: Ip地址中有三个小数点.

let result_list = [];

function recursion_get_number(prefix/* 前缀 */,remain_digits)
{
    // 基准情形1:已经有了四个点:
    let count_dot = 0;
    for(let i=0;i<prefix.length;++i){
        if(prefix[i]=='.')++count_dot;
    }
    if(4==count_dot)return;

    // 基准情形2: 第一个数字是0
    if(remain_digits[0]=='0')return;

    for(let i=1;i<=3;++i){
        let str = remain_digits.substr(0,i);
        let number = Number(str);
        if(255<number)continue;

        // 基准情形3: 正好用完了数字
        if(i==remain_digits.length)
        {
            result_list.push(prefix+remain_digits);
        }
        else
        {
            recursion_get_number(prefix+str+'.',remain_digits.substr(i));
        }
    }
}

recursion_get_number("","190104114239");
console.log(result_list);



function hasTwoHyphens(str) {
    // 使用正则表达式匹配两个'-'
    const matchResult = str.match(/-+/g);
    
    // 如果没有匹配到或者匹配到的数量不是2，返回false
    if (!matchResult || matchResult.length !== 2) {
        return false;
    }
    
    // 如果有两个'-'，返回true
    return true;
}

// 测试
console.log(hasTwoHyphens('abc-x-def')); // 输出: true
console.log(hasTwoHyphens('abc-def')); // 输出: false
console.log(hasTwoHyphens('abc-def-ghi')); // 输出: false